#include <iostream>
using namespace std;
#include <set>

class Data{
friend ostream& operator << (ostream& out, const Data& d);
private:
	char 	ch;
	int 	count;
public:
	Data(char ch, int count = 1)
		:ch(ch),
		count(count)
	{
	
	}
	//Data const * const this;
	void addCount() const
	{
		//const_cast<>()	去掉一个const对象的const属性
		//Data* p = const_cast<Data *const>(this);
		//p->count++;

		//const Data
		Data& d = const_cast<Data&>(*this);
		d.count++;
	}
	//必须是const函数
	bool operator < (const Data& rhs) const
	{
		return this->ch < rhs.ch;
	}
};
ostream& operator << (ostream& out, const Data& d)
{
	out << d.ch << "----->" << d.count;
	return out;
}
int main(int argc,char **argv)
{
	set<Data> mySet;
	string s;
	cout << "input string: ";
	cin >> s;
	for(string::iterator it = s.begin(); it != s.end(); it++){
		Data d(*it);
		pair<set<Data>::iterator, bool> ret = mySet.insert(d);
		if(!ret.second){
			//插入失败
			set<Data>::iterator sit = ret.first;
			sit->addCount();
		}
	}

	for(set<Data>::iterator it = mySet.begin(); it != mySet.end(); it++){
		cout << *it << endl;
	}


	return 0;
}
